Skip to content

Migrate hinge angle injection to sensors simulator#2643

Open
dimorinny wants to merge 1 commit into
google:mainfrom
dimorinny:main
Open

Migrate hinge angle injection to sensors simulator#2643
dimorinny wants to merge 1 commit into
google:mainfrom
dimorinny:main

Conversation

@dimorinny
Copy link
Copy Markdown
Contributor

The cuttlefish_sensor_injection tool does not work with goldfish multihal sensors, meaning hinge angle changes currently have no effect

To fix this, redirect WebRTC hinge angle updates to the sensors simulator instead.

Test: hinge angle is updated from web ui
Bug: 517370262

@dimorinny dimorinny added the kokoro:run Run e2e tests. label Jun 2, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Jun 2, 2026
@dimorinny dimorinny added the kokoro:force-run Trigger a presubmit build unconditionally. label Jun 2, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:force-run Trigger a presubmit build unconditionally. label Jun 2, 2026
Comment on lines +216 to +218
auto sensors_data = sensors_simulator_.GetSensorsData(mask);
std::lock_guard<std::mutex> lock(report_mtx_);
auto result = UpdateSensorsHal(sensors_data, data_channel_, mask);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this was moved from data_reporter_thread_, but note abseil.io/tips/232

Use type deduction only if it makes the code clearer to readers who aren’t familiar with the project, or if it makes the code safer. Do not use it merely to avoid the inconvenience of writing an explicit type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with making sensors_data explicit (std::string) above, the type isn't obvious from GetSensorsData, but I kept result as auto since auto result = …; if (!result.ok()) for Result<void> is the idiom used throughout this file and the wider codebase. Happy to spell it out too if you'd rather go the other way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "idiom used throughout the wider codebase" still doesn't really satisfy the condition of "makes the code clearer to readers who aren't familiar with the project."

Comment thread base/cvd/cuttlefish/host/commands/sensors_simulator/sensors_hal_proxy.cpp Outdated
Comment thread base/cvd/cuttlefish/host/commands/sensors_simulator/sensors_simulator.cpp Outdated
Comment thread base/cvd/cuttlefish/host/frontend/webrtc/sensors_handler.cpp Outdated
element.dataset.adb = true;
}
}
element.dataset.adb = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this still be here? If I understand correctly, the code before amounted to something like "if the device state includes hinge_angle, make sure adb is connected."

As written this commit changes it to "always connect to adb," but I would expect "the hinge angle is not sent via adb" to imply "adb no longer matters for sensors, don't set or unset the adb connection requirement."

I may be misunderstanding what the .adb variable is for. FYI @jemoreira

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the change perspective this makes sense, I'm agree.

However, after checking the getCustomDeviceStateButtonCb implementation, it looks to me like any action on that panel triggers adbShell('cmd device_state state reset'), meaning ADB is executed regardless of whether we change the hinge angle, the lid, or anything else, so I assume the entire panel should be disabled if ADB isn't available.

Do you think I'm missing something?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like adb should have been set regardless of device state including hinge angle or not.

The question that remains is: Is that device reset over adb still necessary if the hinge is handled via sensors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the change where this reset was introduced and another very old change. We used to have buttons triggering the following shell commands:

"shell_command":"dumpsys device_state | grep mCommittedState | grep OPENED && cmd device_state state 0 || cmd device_state state 2",

So device_state can be override via shell_command buttons and to ensure old "override" value isn't affecting the new-coming LID injection , this reset was introduced.

Checking the modern custom actions jsons across the internal tree, I cannot see anything similar and I think we should discourage using device_state this way and always go through the proper sensors.

Taken all of that I would prefer getting rid of this adb reset command (so adb dependency), but want to hear @jemoreira opinion after this context?

The cuttlefish_sensor_injection tool does not work with goldfish
multihal sensors, meaning hinge angle changes currently have no
effect

To fix this, redirect WebRTC hinge angle updates to the sensors
simulator instead.

Test: hinge angle is updated from web ui
Bug: 517370262
Signed-off-by: Dmitrii Merkurev <dimorinny@google.com>
@dimorinny dimorinny added the kokoro:run Run e2e tests. label Jun 3, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Jun 3, 2026
@dimorinny dimorinny requested a review from Databean June 3, 2026 09:51
std::stringstream ss;
ss << x << sensors::INNER_DELIM << y << sensors::INNER_DELIM << z;
CF_EXPECT(SendCommand(sensors::kUpdateRotationVec, ss.str()));
UpdateSensorsUi();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the discussion on on_change_callback_, what's the distinction that requires SetMotion calls UpdateSensorsUi but not SetHingeAngle?

Comment on lines +216 to +218
auto sensors_data = sensors_simulator_.GetSensorsData(mask);
std::lock_guard<std::mutex> lock(report_mtx_);
auto result = UpdateSensorsHal(sensors_data, data_channel_, mask);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "idiom used throughout the wider codebase" still doesn't really satisfy the condition of "makes the code clearer to readers who aren't familiar with the project."

Comment thread base/cvd/cuttlefish/host/commands/sensors_simulator/sensors_simulator.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants